#coding=utf-8
import os
import string
import random
import datetime
from django.conf import settings

def randomize(length=16, charset=string.ascii_letters + string.digits):
    random.seed = (os.urandom(1024))
    return ''.join(random.choice(charset) for i in range(length))

def format_date(date, orig_format, res_format):
    return datetime.datetime.strptime(date, orig_format).strftime(res_format)

def upload_file(f, directory):
    ext = str(f).split(".")[-1]
    filename = "%s.%s" % (randomize(length=8), ext)
    filepath = '%s/%s' % (directory, filename)
    if not os.path.exists(directory):
        os.makedirs(directory)
    with open(filepath, 'wb+') as destination:
        for chunk in f.chunks():
            destination.write(chunk)
    return filename

periodDef = datetime.date.today().month
yearDef = datetime.date.today().year

MODULES_POWER_STATUS_CHOICES = (
     ('0','新入网客户'),
     ('1','正常用电客户'),
     ('2','欠缴正常用电客户'),
     ('3','欠缴停电用户'),
     ('4','黑名单用户'),
     ('5','合同执行完成用户'),
     ('10','追踪用户'),
)
